package com.maiyuren.fishkit.utils

import androidx.compose.runtime.MutableState
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.launch

fun <T> MutableState<T>.watch(onChange: (v: T)->Unit) {
    val flow = MutableStateFlow(this.value)
    GlobalScope.launch(Dispatchers.Main) {
        flow.collect {
            onChange(it)
        }
    }
}